package com.utils;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class BaseCache {

    private  Cache<String,Object> tenMinuteCache=CacheBuilder.newBuilder()
                //初始化缓存大小
                .initialCapacity(10)
                //最大值
                .maximumSize(100)
                //并发数目
                .concurrencyLevel(5)
                //缓存过期时间
                .expireAfterWrite(600,TimeUnit.SECONDS)
                //统计缓存命中率
                .recordStats()
                .build();

    private Cache<String,Object> oneHourCache=CacheBuilder.newBuilder()
            .initialCapacity(35)
            .maximumSize(100)
            .concurrencyLevel(5)
            .recordStats()
            //一小时过期
            .expireAfterWrite(1,TimeUnit.HOURS)
            .build();







    public Cache<String, Object> getOneHourCache() {
        return oneHourCache;
    }

    public void setOneHourCache(Cache<String, Object> oneHourCache) {
        this.oneHourCache = oneHourCache;
    }

    public Cache<String, Object> getTenMinuteCache() {
        return tenMinuteCache;
    }

    public void setTenMinuteCache(Cache<String, Object> tenMinuteCache) {
        this.tenMinuteCache = tenMinuteCache;
    }
}
